const mysql = require('mysql2/promise');

const dbConfig = {
  host: process.env.DB_HOST || '127.0.0.1',
  port: process.env.DB_PORT || 3306,
  database: 'node_dev_db',
  user: process.env.DB_USER || 'root',
  password: process.env.DB_PASS || '123456',
  waitForConnections: true,
  connectionLimit: 10,
  queueLimit: 0,
  timezone: '+08:00'
};



// 创建连接池
const pool = mysql.createPool(dbConfig);

// 测试数据库连接
const testConnection = async () => {
  try {
    const connection = await pool.getConnection();
    console.log('数据库连接成功1');
    connection.release();
  } catch (error) {
    console.error('数据库连接失败:', error.message);
  }
};

module.exports = {
  pool,
  testConnection
};
